package
{
	import com.lang.IndexLang;
	
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class Index extends Sprite
	{
		public var args :Object;
		
		private var _tf :TextField;
		private var _effectLoader :Loader;
		private var _mainLoader :Loader;
		
		public function Index()
		{
			addEventListener(Event.ADDED_TO_STAGE, addedToStage);
		}
		
		private function addedToStage( event :Event ) :void {
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			_tf = new TextField();
			addChild( _tf );
			
			_tf.autoSize = TextFieldAutoSize.LEFT;
			_tf.text = IndexLang.Init;
			_tf.textColor = 16777215;
			_tf.selectable = false;
			
			_effectLoader = new Loader();
			addChild( _effectLoader );
			
			_mainLoader = new Loader();
			
			addEvent();
			
			_effectLoader.load(new URLRequest( Config.ResourcesPathPrefix + "assets/init_effect.swf" ) );
			_mainLoader.load(new URLRequest( Config.ResourcesPathPrefix + "Main.swf" ) );
			
			center();
			
		}
		
		private function addEvent() :void {
			_mainLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, ch);
			stage.addEventListener(Event.RESIZE, center);
		}
		
		private function ch(event:Event) : void
		{
			removeEvent();
			stage.addChild(_mainLoader.content);
		}
		
		private function removeEvent() : void
		{
			_mainLoader.removeEventListener(Event.COMPLETE, ch);
			stage.removeEventListener(Event.RESIZE, center);
		}
		
		private function center( event :Event = null ) :void {
			_tf.x = (stage.stageWidth - _tf.width) / 2;
			_tf.y = (stage.stageHeight - _tf.height) / 2;
			_effectLoader.x = (stage.stageWidth - 40) / 2;
			_effectLoader.y = _tf.y - 40 - 5;
		}
	}
}